package Skeleton;

import java.io.BufferedReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 char wichCase = '0';
		 java.io.InputStreamReader reader = new java.io.InputStreamReader(System.in);
		 java.io.BufferedReader buffer = new BufferedReader(reader);
		 
		 System.out.println("Szoftver labor 4\n6. Szkeleton by Team Parizer");
		 
		 try{
			 while(wichCase != 'q' && wichCase != 'Q'){
				 System.out.println("\nLehetseges esetek:");
				 System.out.println("\ta - \"A\" kapcsolas");
				 System.out.println("\tb - \"B\" kapcsolas");
				 System.out.println("\tc - \"C\" kapcsolas");
				 System.out.println("\td - \"D\" kapcsolas");
				 System.out.println("\te - \"E\" kapcsolas");
				 System.out.println("\tf - \"F\" kapcsolas");
				 System.out.println("");
				 System.out.println("\tq - Kilepes a Skeletonbol\n");
				 
				 System.out.print("Valasztott eset: ");
				 String line = buffer.readLine();
				 wichCase = line.isEmpty() ?  '0' : line.charAt(0);
				 
				 switch (wichCase){
				 	case 'a':
				 	case 'A':
				 		System.out.println('\n'+"\"A\" eset");
				 		caseA();
				 		break;
				 	case 'b':
				 	case 'B':
				 		System.out.println('\n'+"\"B\" eset");
				 		caseB();
				 		break;
				 	case 'c':
				 	case 'C':
				 		System.out.println('\n'+"\"C\" eset");
				 		caseC();
				 		break;
				 	case 'd':
				 	case 'D':
				 		System.out.println('\n'+"\"D\" eset");
				 		caseD();
				 		break;
				 	case 'e':
				 	case 'E':
				 		System.out.println('\n'+"\"E\" eset");
				 		caseE();
				 		break;
				 	case 'f':
				 	case 'F':
				 		System.out.println('\n'+"\"F\" eset");
				 		caseF();
				 		break;
				 	
				 
				 	default :
				 		System.out.println('\n');
				 }
				 
				 
			 }
		 } catch (java.io.IOException e){
			 System.out.println(e.getMessage());			 
		 }

	}
	
	public static void caseA(){
		BreadBoard bb = new BreadBoard();
		Switch s = new Switch();
		LED led = new LED();

		bb.addBlock(s);
		bb.addBlock(led);
		
		bb.addWire(new Wire(led, led.input, s, s.output));
		bb.userValidationEnabled = false;
		bb.startSimulation();		
		
	}
	
	public static void caseB(){
		BreadBoard bb = new BreadBoard();
		Switch s = new Switch();
		NotGate not = new NotGate();
		LED led = new LED();
		
		Wire w1 = new Wire(not, not.inputs.get(0), s, s.output);
		Wire w2 = new Wire(led, led.input, not, not.output);
			
		bb.addBlock(s);
		bb.addBlock(not);
		bb.addBlock(led);
		
		bb.addWire(w1);
		bb.addWire(w2);
		
		bb.userValidationEnabled = false;
		bb.startSimulation();		
		
	}
	
	public static void caseC(){
		BreadBoard bb = new BreadBoard();
		Switch s1 = new Switch();
		Switch s2 = new Switch();
		AndGate and = new AndGate();
		LED led = new LED();
		
		Wire w1 = new Wire(and, and.inputs.get(0), s1, s1.output);
		Wire w2 = new Wire(and, and.inputs.get(1), s2, s2.output);
		Wire w3 = new Wire(led, led.input, and, and.output);
		
		bb.addBlock(s1);
		bb.addBlock(s2);
		bb.addBlock(and);
		bb.addBlock(led);
		
		bb.addWire(w1);
		bb.addWire(w2);
		bb.addWire(w3);
		
		bb.userValidationEnabled = false;
		bb.startSimulation();		
		
	}
	
	public static void caseD(){
		BreadBoard bb = new BreadBoard();
		Switch s = new Switch();
		NotGate not = new NotGate();
		AndGate and = new AndGate();
		LED led = new LED();
		
		Wire w1 = new Wire(and, and.inputs.get(0), s, s.output);
		Wire w2 = new Wire(and, and.inputs.get(1), not, not.output);
		Wire w3 = new Wire(not, not.inputs.get(0), and, and.output);
		Wire w4 = new Wire(led, led.input, not, not.output);
		
		bb.addBlock(s);
		bb.addBlock(not);
		bb.addBlock(and);
		bb.addBlock(led);
		
		bb.addWire(w1);
		bb.addWire(w2);
		bb.addWire(w3);
		bb.addWire(w4);
		
		bb.userValidationEnabled = false;
		bb.startSimulation();		
		
	}
	
	public static void caseE(){
		BreadBoard bb = new BreadBoard();
		Switch s1 = new Switch();
		Switch s2 = new Switch();
		AndGate and = new AndGate();
		LED led = new LED();
		
		Wire w1 = new Wire(and, and.inputs.get(0), s1, s1.output);
		Wire w2 = new Wire(and, and.inputs.get(1), s2, s2.output);
		Wire w3 = new Wire(led, led.input, and, and.output);
		
		led.input.setConnectedOutput(and.output);
		and.inputs.get(0).setConnectedOutput(s1.output);
		and.inputs.get(1).setConnectedOutput(s2.output);
		
		bb.addBlock(s1);
		bb.addBlock(s2);
		bb.addBlock(and);
		bb.addBlock(led);
		
		bb.addWire(w1);
		bb.addWire(w2);
		bb.addWire(w3);
		bb.deleteBlock(and);
	}
	
	public static void caseF(){
		BreadBoard bb = new BreadBoard();
		Switch s1 = new Switch();
		AndGate and = new AndGate();
		LED led = new LED();
		
		Wire w1 = new Wire(and, and.inputs.get(0), s1, s1.output);
		Wire w3 = new Wire(led, led.input, and, and.output);
		
		bb.addBlock(s1);
		bb.addBlock(and);
		bb.addBlock(led);
		
		bb.addWire(w1);
		bb.addWire(w3);
		
		bb.userValidationEnabled = true;
		try{
			bb.startSimulation();		
		}catch(java.lang.NullPointerException e){
			System.out.println(e.toString()+" Nem is volt valid az aramkor!");
		}
	}

}
